<template>
	<!-- 	<view class="comment-bottom">
		<view class="comment-input" v-show="showInput">
			<u--input @input="listenInput" type="text" v-model="query.keywords" placeholder="请输入评论内容" shape="circle"
				clearable></u--input>
		</view>
		<view class="button-box">
			<view v-if="!like" class="btn-icon-like" @click="clickLike">
				<view class="icon">
					<img style="width: 50rpx; height: 55rpx;" src="../../static/img/tabbar/shouting_2 (1).png"></img>
				</view>
				<view class="text">
					12
				</view>
			</view>
			<view v-else class="btn-icon-like" @click="cancelLike">
				<view class="icon">
					<img style="width: 50rpx; height: 55rpx;" src="../../static/img/tabbar/shouting_2.png"></img>
				</view>
				<view class="text">
					12
				</view>
			</view>
			<view class="btn-icon first" @click="clickPinglun">
				<view class="icon">
					<img style="width: 50rpx; height: 55rpx;" src="../../static/img/tabbar/pinglun.png"></img>
				</view>
			</view>
			<view class="btn-icon">
				<view class="icon">
					<img style="width: 50rpx; height: 55rpx;" src="../../static/img/tabbar/fenxiang.png"></img>
				</view>
			</view>
			<view class="btn-icon">
				<view class="icon">
					<img style="width: 50rpx; height: 55rpx;" src="../../static/img/tabbar/tupian.png"></img>
				</view>
			</view>
		</view>
	</view> -->
	<view class="bottom-comment">
		<!-- 左边静态输入框 -->
		<view class="disableinput" @click="showTextarea">
			<!-- 微风不燥，评论正好 -->
			{{sentences[Math.floor(Math.random() * 8)]}}
		</view>
		<!-- 文章总点赞 -->
		<view v-if="!item.liked" class="bottom-item first" @click="clickLike">
			<img class="item-icon" style="width: 40rpx; height: 40rpx;"
				src="../../static/img/tabbar/shouting_2 (2).png"></img>
			<text class="item-text">{{ item.likeTotal }}</text>
		</view>
		<view v-else class="bottom-item first" @click="cancelLike">
			<img class="item-icon" style="width: 40rpx; height: 40rpx;"
				src="../../static/img/tabbar/shouting_2 (3).png"></img>
			<text class="item-text">{{ item.likeTotal }}</text>
		</view>
		<!-- 文章总评论 -->
		<view class="bottom-item second" @click="showTextarea">
			<img class="item-icon" style="width: 40rpx; height: 40rpx;"
				src="../../static/img/tabbar/pinglun (1).png"></img>
			<text class="item-text">{{ commentTotal }}</text>
		</view>
		<!-- 文章总收藏 -->
		<!-- 	<view class="bottom-item">
			<img class="item-icon" style="width: 40rpx; height: 40rpx;" src="../../static/img/tabbar/fx.png"></img>
			<text class="item-text">{{ 10 }}</text>
		</view> -->
		<!-- 发布评论模态框 -->
		<u-popup :show="show" mode="bottom" @close="close" @open="open">
			<view class="comment-input-wrap" :style="{'margin-bottom': inputTop + 'rpx'}">
				<view class="comment-textarea-box">
					<textarea :adjustPosition='false' @input="listenInput" @keyboardheightchange="handleKeyboardChange"
						class="comment-textarea" :maxlength="600" :placeholder="customPlaceholder" />
					<view class="limit">{{commentContent.length}} / 600</view>
				</view>
				<view class="relase-btn">
					<!-- 发布 -->
					<view class="relase" @click="sendMsg">
						发布</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		sendComment,
	} from '../../api/comment';
	import {
		like,
		cancelLike
	} from '../../api/article';
	export default {
		name: "bottom-comment",
		data() {
			return {
				sentences: [
					"微风不燥，评论正好", "爱评论的人运气都不差", "求同存异，和谐交流", "此刻的你想说什么", "爱评论的人运气都不差", "求同存异，和谐交流", "留下点什么再走吧",
					"善语结善缘，恶言伤人心",
					"新的风暴已经出现，你的妙评何时再现"
				],
				commentTotal: "",
				commentContent: "",
				showInput: false,
				show: false,
				inputTop: 0,
				aid: 0, //文章id
				type: 0,
				rootId: -1, //根评论id
				toCommentId: -1, //所回复评论的id
				toCommentUserId: -1, //所评论的用户ids
			}
		},
		props: {
			item: {
				type: Object,
				default () {
					return {
						"likeTotal": 0,
						// "commentTotal": 0,
						"liked": false,
						"aid": 0
					}
				}
			}
		},
		mounted() {
			// 接收comment-box组件传来的值
			uni.$on('changeTotal', num => {
				this.commentTotal = num
			})
			console.log("botomNav1");
		},
		methods: {
			callParentMethod() {
				// 调用父组件方法
				this.$emit('callParentFunc', this.item.aid);
			},
			sendMsg() {
				// console.log(this.commentContent);
				sendComment(this.type, this.item.aid, this.rootId, this.toCommentId, this.toCommentUserId, this
						.commentContent)
					.then((
						response) => {
						this.show = false
						this.commentContent = '';
						this.rootId = -1;
						this.toCommentId = -1;
						this.toCommentUserId = -1;
						uni.showToast({
							title: '评论需要审核',
							duration: 2000
						});
					})
			},
			handleKeyboardChange() {
				// 监听窗口大小变化
				uni.onKeyboardHeightChange((res) => {
					console.log(res);
					if (res.height) {
						this.inputTop = res.height + 300; // 键盘弹出时，输入框向上移动
					} else {
						this.inputTop = 0; // 键盘收起时，输入框恢复原位
					}
				});
				console.log(this.inputTop);
			},
			showTextarea() {
				this.show = true
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			},
			listenInput(e) {
				this.commentContent = e.detail.value
				console.log(this.commentContent.length);
			},
			clickLike() {
				console.log(this.item.aid);
				like(this.item.aid).then(() => {
					this.callParentMethod()
					uni.showToast({
						title: '收藏成功',
						duration: 1000
					});
				})
			},
			cancelLike() {
				cancelLike(this.item.aid).then(() => {
					this.callParentMethod()
					uni.showToast({
						title: '取消收藏',
						duration: 1000
					});
				})
			},
			clickPinglun() {
				this.showInput = !this.showInput
			}
		}
	}
</script>

<style lang="scss">
	.bottom-comment {
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 80;
		width: 100vw;
		min-height: 8vh;
		background-color: #fff;
		box-shadow: 0 0 8rpx 4rpx #f7f7f7;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 28rpx;

		.disableinput {
			width: 54%;
			height: 70rpx;
			background-color: #f6f6f6;
			border-radius: 35rpx;
			margin-right: 30rpx;
			font-size: 20rpx;
			color: #767676;
			padding-left: 16rpx;
			display: flex;
			align-items: center;
		}

		.bottom-item {
			flex: 1;
			display: flex;
			margin-right: 10rpx;
			align-items: center;

			&.first {
				border-radius: 40rpx;
				background-color: rgb(85, 170, 255);
				padding: 0 25rpx;
			}

			&.second {
				padding-left: 30rpx;

				text {
					color: black;
				}
			}

			.item-icon {
				font-size: 38rpx;
				padding-right: 10rpx;
			}

			.isUp {
				color: $uni-color-primary;
			}

			.item-text {
				font-size: 30rpx;
				color: white;
			}
		}

		.comment-input-wrap {
			padding: 20rpx 30rpx;
			display: flex;
			flex-direction: column;


			.comment-textarea-box {
				position: relative;

				.comment-textarea {
					border-radius: 20rpx;
					height: 160rpx;
					width: auto;
					background-color: #f6f6f6;
					font-size: 26rpx;
					padding: 20rpx;
				}

				.limit {
					// 定位到textarea 的 右下角
					position: absolute;
					right: 20rpx;
					bottom: 20rpx;
					font-size: 20rpx;
					color: #767676;
				}
			}

			.relase-btn {
				display: flex;
				justify-content: space-between;
				// align-items: center;
				margin-top: 10rpx;

				.limit {
					font-size: 24rpx;
					color: #767676;
				}

				.relase {
					background-color: rgb(61, 187, 175);
					border-radius: 10rpx;
					font-size: 26rpx;
					color: #fff;
					position: absolute;
					right: 35rpx;
					padding: 10rpx 20rpx;
				}
			}
		}

	}

	// .comment-bottom {
	// 	position: fixed;
	// 	bottom: 0;
	// 	z-index: 99999999999;
	// 	padding: 30rpx;

	// 	.button-box {
	// 		padding-top: 20rpx;
	// 		display: flex;
	// 		justify-content: space-between;

	// 		.text {
	// 			color: white;
	// 			font-size: 32rpx;
	// 		}

	// 		.btn-icon-like {
	// 			display: flex;
	// 			justify-items: center;
	// 			align-items: center;
	// 			padding-left: 30rpx;
	// 			width: 28%;
	// 			border-radius: 40rpx;
	// 			height: 60rpx;
	// 			background-color: rgb(85, 170, 255);
	// 			margin-right: 70rpx;

	// 			.icon {
	// 				padding-right: 10rpx;
	// 			}
	// 		}

	// 		.btn-icon {
	// 			display: flex;
	// 			justify-items: center;
	// 			align-items: center;
	// 			width: 20%;
	// 			height: 60rpx;
	// 		}
	// 	}
	// }
</style>